package com.zcdyy.rentalofhouse.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zcdyy.rentalofhouse.R;
import com.zcdyy.rentalofhouse.bean.AllRental;
import com.zcdyy.rentalofhouse.bean.SaleHouse;
import com.zcdyy.rentalofhouse.bean.ShopRent;
import com.zcdyy.rentalofhouse.utils.BaseTranslucentActivity;
import com.zcdyy.rentalofhouse.utils.ImageLoaderUtils;

public class SaleHouseDetailActivity extends BaseTranslucentActivity implements View.OnClickListener {
    private TextView tvTitle;
    private ImageView ivHousePic;
    private TextView tvHouseName;
    private TextView tvHouseMoney;
    private TextView tvTingShiShow;
    private TextView tvHouseMianjiShow;
    private TextView tvHouseZhuangxiuShow;
    private TextView tvHouseLouCeng;
    private TextView tvHouseQuyuShow;
    private TextView tvHouseAllloucengShow;
    private TextView tvHouseShoujiamoney;
    private TextView tvHouseXiaoquContent;
    private TextView tvHouseDesc;
    private TextView tvLianxiren;
    private TextView tvShoujihao;
    private LinearLayout ll_phone;
    private LinearLayout ll_sms;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_house_detail);
        initView();
        initData();
        initTitle();
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getBundleExtra("bundle");
            //String title = bundle.getString("title");
            //tvTitle.setText(title);
            SaleHouse saleHouse = (SaleHouse) bundle.getSerializable("allSale");
            ImageLoaderUtils.loadImage(this, saleHouse.getPic().getFileUrl(), ivHousePic);
            tvHouseName.setText(saleHouse.getBiaoTi());
            tvHouseMoney.setText(saleHouse.getShouJia());
            tvTingShiShow.setText(saleHouse.getShi()+"室"+saleHouse.getTing()+"厅"+saleHouse.getWei()+"位");
            tvHouseMianjiShow.setText(saleHouse.getMiaoJi());
            tvHouseZhuangxiuShow.setText(saleHouse.getZhuangXiu());
            tvHouseLouCeng.setText(saleHouse.getLouCeng()+"层"+"");
            tvHouseQuyuShow.setText(saleHouse.getQuYu());
            tvHouseAllloucengShow.setText(saleHouse.getZongLouCeng()+"楼"+"");
            tvHouseShoujiamoney.setText(saleHouse.getShouJia());
            tvHouseXiaoquContent.setText(saleHouse.getXiaoQu());
            tvHouseDesc.setText(saleHouse.getMiaoShu());
            tvLianxiren.setText(saleHouse.getLianXiRen());
            tvShoujihao.setText(saleHouse.getShouJiHao());
        }
    }

    private void initView() {
        ll_phone = (LinearLayout) findViewById(R.id.ll_phone);
        ll_sms = (LinearLayout) findViewById(R.id.ll_sms);
        tvTitle = (TextView) findViewById(R.id.top_tv_title);
        ivHousePic = (ImageView) findViewById(R.id.iv_house_pic);
        tvHouseName = (TextView) findViewById(R.id.tv_house_name);
        tvHouseMoney = (TextView) findViewById(R.id.tv_house_money);
        tvTingShiShow = (TextView) findViewById(R.id.tv_tingshi_show);
        tvHouseMianjiShow = (TextView) findViewById(R.id.tv_house_mianji_show);
        tvHouseZhuangxiuShow = (TextView) findViewById(R.id.tv_house_zhuangxiu_show);
        tvHouseLouCeng = (TextView) findViewById(R.id.tv_house_louceng);
        tvHouseQuyuShow = (TextView) findViewById(R.id.tv_house_quyu_show);
        tvHouseAllloucengShow = (TextView) findViewById(R.id.tv_house_alllouceng_show);
        tvHouseShoujiamoney = (TextView) findViewById(R.id.tv_house_shoujiamoney);
        tvHouseXiaoquContent = (TextView) findViewById(R.id.tv_house_xiaoqu_content);
        tvHouseDesc = (TextView) findViewById(R.id.tv_house_desc);
        tvLianxiren = (TextView) findViewById(R.id.tv_lianxiren);
        tvShoujihao = (TextView) findViewById(R.id.tv_shoujihao);

    }

    private void initTitle() {
        tvTitle.setText("二手房详情");
        ll_phone.setOnClickListener(this);
        ll_sms.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.ll_phone:
                Intent intent = new Intent();
                intent.setAction("android.intent.action.CALL");
                intent.setData(Uri.parse("tel:"+ tvLianxiren.getText().toString()));//mobile为你要拨打的电话号码，模拟器中为模拟器编号也可
                startActivity(intent);

                break;
            case  R.id.ll_sms:
                Uri smsToUri = Uri.parse("smsto:"+tvLianxiren.getText().toString());
                Intent mIntent = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
                mIntent.putExtra("sms_body", "您好，我对你的房屋很感兴趣。方便联系一下么？");
                startActivity( mIntent );
                break;
        }
    }
}
